package ${package.Controller};

import com.maqh.demo.common.pojo.PageVO;
import com.maqh.demo.common.pojo.Rest;
import com.maqh.demo.common.util.RestUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.*;
import ${package.Service}.${table.serviceName};
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import javax.validation.constraints.NotNull;

<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@Api(tags = {"${table.comment!}"})
@RestController
<#else>
@Controller
</#if>@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>class ${table.controllerName}<#if superControllerClass??>:${superControllerClass}()</#if><#else><#if superControllerClass??>public class ${table.controllerName} extends ${superControllerClass}{<#else>public class ${table.controllerName} {</#if>

    @Autowired
<#--    private ${table.serviceName} ${(table.serviceName?substring(1))?uncap_first};-->
    private ${table.serviceName} ${(table.serviceName)?uncap_first};


    @ApiOperation(value = "新增${table.comment!}")
    @PostMapping()
    public Rest add(@RequestBody ${entity}AddForm form){
        ${(table.serviceName)?uncap_first}.add(form);

        return RestUtil.success();
    }

    @ApiOperation(value = "删除${table.comment!}")
    @PostMapping()
    public Rest delete(@NotNull Long id){
        ${(table.serviceName)?uncap_first}.delete(id);

        return RestUtil.success();
    }

    @ApiOperation(value = "更新${table.comment!}")
    @PostMapping()
    public Rest update(@RequestBody ${entity}UpdateForm form){
        ${(table.serviceName)?uncap_first}.update(form);

        return RestUtil.success();
    }

    @ApiOperation(value = "查询${table.comment!}分页数据")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "currPage", value = "页码"),
        @ApiImplicitParam(name = "pageSize", value = "每页条数")
    })
    @GetMapping()
    public Rest<PageVO> page(@NotNull Integer currPage, @NotNull Integer pageSize){
        IPage<${entity}DTO> iPage = ${(table.serviceName)?uncap_first}.page(currPage, pageSize);

        PageVO<${entity}TableVO> cardParkVOPageVO = JsonUtil.pageTransform(iPage, ${entity}TableVO.class);
        return RestUtil.success();
    }

    @ApiOperation(value = "根据id查询${table.comment!}")
    @GetMapping("get-by-id")
    public Rest<${entity}InfoVO> getById(@NotNull Long id){
        ${(table.serviceName)?uncap_first}.getById(id);

        return RestUtil.success();
    }

}
</#if>